package com.pcj.service.impl;

import com.pcj.mapper.CoverMapper;
import com.pcj.service.CoverService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lei.xiang
 * @date 2025/4/3 13:06
 */
@Service
public class CoverServiceImpl implements CoverService {

    @Resource
    private CoverMapper coverMapper;

    @Override
    public List<String> getAllTableNames() {

        // 先获取所有表名

        return null;
    }

    @Override
    public void oneTable(String tableName, String fieldName) {

        List<String> fields = new ArrayList<>();
        fields.add(fieldName);
        // 1、拿到数据库中所有图片的url
        List<Map<String, Object>> oneTable = coverMapper.getOneTable(tableName, fields, null);

        // 2、拿到图片,搞到自己本地,或者整到自己的文件存储中
        for (Map<String, Object> map : oneTable) {
            System.out.println(map);


        }


        // 3、更新数据库为自己的url
        List<Map<String, Object>> updates = new ArrayList<>();
        for (Map<String, Object> map : oneTable) {
            Map<String, Object> update = new HashMap<>();
            update.put("originalValue", map.get(fieldName)); // 原始值
            update.put("newValue", "new_url"); // 新值，根据实际情况设置
            updates.add(update);
        }

        coverMapper.batchUpdateByOriginalValue(updates);

    }
}
